package com.example.room.dao;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Transaction;

import com.example.room.UserWithOrders;
import com.example.room.entity.Order;

import java.util.List;

@Dao
public interface OrderDao {

    // 联表查询：获取指定用户及其订单信息
    @Transaction
    @Query("SELECT * FROM users WHERE user_id = :userId")
    LiveData<UserWithOrders> getUserWithOrders(long userId);

    // 插入订单
    @Insert
    void insert(Order order);

    // 查询所有订单
    @Query("SELECT * FROM orders")
    LiveData<List<Order>> getAllOrders();

}
